$(document).ready(function() {
	var collapseIcon = $("#alt-login-collapse");
	var altLogin = $("#alt-login");
	var altLoginText = altLogin.children('#alt-login-text');
	var collapsables = altLoginText.siblings();

	//Collapse if not failed login attempt
	if(! $("#login-failure").length) {
		altLoginText.addClass('collapsed');
		collapsables.hide();
	}

	//Add expand icon
	collapseIcon.addClass('icon-chevron-right');

	//Add Collapse/Expand-listener
	altLoginText.on('click', function() {
		//Toggle expand/collapse icon
		collapseIcon.toggleClass('icon-chevron-right').toggleClass('icon-chevron-down');

		//Show/Hide and toggle expanded/collapsed classes
		if(altLoginText.hasClass('collapsed')) {
			collapsables.slideDown();
			altLoginText.removeClass('collapsed');
		} else {
			//Update css after slide is complete
			collapsables.slideUp(function() {
				altLoginText.addClass('collapsed');
			});
		}
		
	});
});